package com.dk.code;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @author zh
 * @Description TODO
 * @createTime 2023/4/20
 */
@Component
public class CodeFectory implements ApplicationRunner {

    //把A1 A2 A3放入到集合中统一处理
    @Autowired
    List<CodeService> list = new ArrayList<>();
    public static HashMap<String,CodeService> map = new HashMap<String,CodeService>();

    @Override
    public void run(ApplicationArguments args) throws Exception {
        for(CodeService code:list){
            Class<? extends CodeService> aClass = code.getClass();

            //从注解中获取name值
            String s = aClass.getAnnotation(CodeType.class).codeType();
           map.put(s, code);
            System.out.println(map);
        }
    }
}
